﻿using System;
using System.Collections.Generic;

namespace MySqlManager.DatabaseBuilder
{
    /// <summary>
    /// Dictionary containing all the variable types supported to be converted from C# to MySQl
    /// </summary>
    public class SupportedTypesDictionary
    {
        private static Dictionary<Type, string> supportedTypes = new Dictionary<Type, string>()
        {
            {typeof(sbyte), "tinyint"},
            {typeof(byte), "tinyint UNSIGNED"},
            {typeof(short), "smallint"},
            {typeof(ushort), "smallint UNSIGNED"},
            {typeof(int), "int"},
            {typeof(uint), "int UNSIGNED"},
            {typeof(long), "bigint"},
            {typeof(ulong), "bigint UNSIGNED"},
            {typeof(string), "text"},
            {typeof(byte[]), "blob"}
        };

        /// <summary>
        /// Gets the specified variable type as MySQl variable type
        /// </summary>
        /// <param name="type">Type of the C# variable</param>
        /// <returns>returns the MySQl variable type as string</returns>
        public static string GetTypeMeaning(Type type)
        {
            if (supportedTypes.ContainsKey(type))
                return supportedTypes[type];
            throw new Exception("Not supported type " + type);

        }

        /// <summary>
        /// Adds a new tranlator from C# variable type to MySQl variable type
        /// </summary>
        /// <param name="type">Type of the C# variable</param>
        /// <param name="value">Type of the MySQl variable as string</param>
        public static void AddOrUpdateTypeMeaning(Type type, string value)
        {
            if (supportedTypes.ContainsKey(type))
                supportedTypes[type] = value;
            supportedTypes.Add(type, value);
            
        }
    }
}